package co.edu.unal.satacredito.database.administration.singleton;

import java.net.UnknownHostException;

import co.edu.unal.satacredito.database.administration.exceptions.DAOException;
import co.edu.unal.satacredito.database.connection.TransactionDatastoreFactory;

import com.google.code.morphia.Datastore;
import com.mongodb.MongoException;

public final class SingletonDataStore {
	
	private static SingletonDataStore instance;
	private Datastore dataStore;
	
	private SingletonDataStore() throws DAOException{
		try {
			this.setDataStore(TransactionDatastoreFactory.createDatastore());
		} catch (UnknownHostException | MongoException e) {
			throw new DAOException(e.getMessage());
		}
		
	}
	
	public static synchronized SingletonDataStore getInstance() throws DAOException{
		if(instance==null)
			instance = new SingletonDataStore();
		return instance;
	}

	public Datastore getDataStore() {
		return dataStore;
	}

	public void setDataStore(Datastore dataStore) {
		this.dataStore = dataStore;
	}

}
